package com.awspaas.user.apps.cpq.controller;

import java.math.BigDecimal;
import java.util.List;

import org.jsoup.Jsoup;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;
import com.alibaba.fastjson.JSONObject;

public class CPQ_getEchartsHtmlPageWeb {

	public String getEchartsHtmlPage(UserContext userContext, String cLF, String rGF, String wXWG, String cGF, String zZF,
			String xMCBYS, String lRJE, String sBSJ, String aZF, String aZFLRJE,String AZFSJ, String ySFY, String gLF,
			String qTFYGDJE, String xMZBJ, String others) {
		try {
			/**
			 * 设备成本饼状图：材料费、人工费、外协费、采购费、制造费 后面的子项可以新增       
			 *  项目基准价饼状图:设备成本、安装费、运输费、管理、利润、税金、其他费用
			 */
			JSONObject jsonObject=new JSONObject();
			JSONObject json1=new JSONObject();
			String sql="select SUM(CLF) as CLF, SUM(CGF) as CGF,"
					+ "SUM(RGF) as RGF,SUM(WXWG) as WX,SUM(DJ) as DJ "
					+ "from  BO_EU_CPQ_SYSTEM_PRICE "
					+ "where  BINDID=?  ";
			RowMap map=DBSql.getMap(sql, new Object[] {others});
			if(null!=map&&!map.isEmpty()) {
				cLF=map.getString("CLF");
				rGF=map.getString("RGF");
				wXWG=map.getString("WX");
				cGF=map.getString("CGF");
			}
			BO bo=SDK.getBOAPI().query("BO_EU_CPQ_PROJECT_MSG").bindId(others).detail();
			zZF=bo.getString("ZZF");
			ySFY=bo.getString("YSFY");
			json1.put("材料费",cLF.isEmpty()?"0":cLF );
			json1.put("人工费",rGF.isEmpty()?"0":rGF);
			json1.put("外协费",wXWG.isEmpty()?"0":wXWG);
			json1.put("采购费", cGF.isEmpty()?"0":cGF);
			json1.put("制造费",zZF.isEmpty()?"0":zZF);
			json1.put("运输费", ySFY.isEmpty()?"0":ySFY);
			xMCBYS=bo.getString("XMCBYS").isEmpty()?"0":bo.getString("XMCBYS");
			 BigDecimal xmcb=new BigDecimal(xMCBYS);	
			String other=(String) SDK.getBOAPI().getByProcess("BO_EU_CPQ_PROJECT_MSG", others, "OTHER");
			if(!other.isEmpty()) {
				JSONObject otherJson= JSONObject.parseObject(other);
				if(null!=other&&otherJson.size()>0) {
					for (String  key : otherJson.keySet()) {
						String vaule= otherJson.getString(key);
						BigDecimal num1=new BigDecimal(vaule.isEmpty()?"0":vaule);	
						xmcb=xmcb.add(num1);
						json1.put(key, vaule);
					}
				}
			}
			
			jsonObject.put("设备成本", json1);
			JSONObject json=new JSONObject();
			lRJE=bo.getString("LRJE").isEmpty()?"0":bo.getString("LRJE");
			aZFLRJE=bo.getString("AZFLRJE").isEmpty()?"0":bo.getString("AZFLRJE");
			sBSJ=bo.getString("SBSJ").isEmpty()?"0":bo.getString("SBSJ");
			AZFSJ=bo.getString("AZFSJ").isEmpty()?"0":bo.getString("AZFSJ");
			aZF=bo.getString("AZF").isEmpty()?"0":bo.getString("AZF");
			qTFYGDJE=bo.getString("QTFYGDJE").isEmpty()?"0":bo.getString("QTFYGDJE");
		String 	YSFLR=bo.getString("YSFLR").isEmpty()?"0":bo.getString("YSFLR");
		String  YSFSJ=bo.getString("YSFSJ").isEmpty()?"0":bo.getString("YSFSJ");
			 BigDecimal sblr=new BigDecimal(lRJE.isEmpty()?"0":lRJE);	
			 BigDecimal azflr=new BigDecimal(aZFLRJE.isEmpty()?"0":aZFLRJE);	
			 BigDecimal sbsj=new BigDecimal(sBSJ.isEmpty()?"0":sBSJ);	
			 BigDecimal azfsj=new BigDecimal(AZFSJ.isEmpty()?"0":AZFSJ);	
			 BigDecimal ysfsj=new BigDecimal(YSFSJ.isEmpty()?"0":YSFSJ);	
			 BigDecimal ysflr=new BigDecimal(YSFLR.isEmpty()?"0":YSFLR);
			 BigDecimal ysfy=new BigDecimal(ySFY.isEmpty()?"0":ySFY);	
			json.put("设备成本", xmcb.add(ysfy));
			json.put("安装费", aZF.isEmpty()?"0":aZF);
			//json.put("运输费", ySFY.isEmpty()?"0":ySFY);
			//json.put("管理费", gLF.isEmpty()?"0":gLF);
			json.put("利润",sblr.add(azflr).add(ysflr));
			json.put("税金", sbsj.add(azfsj).add(ysfsj));
			json.put("其他费用", qTFYGDJE.isEmpty()?"0":qTFYGDJE);
			jsonObject.put("项目基准价", json);
			System.out.println(jsonObject);
			SDK.getBOAPI().updateByBindId("BO_EU_CPQ_PROJECT_MSG", others, "OTHER", other);

			return jsonObject.toJSONString();
		} catch (Exception e) {
			throw  e;
		}
		
	}

}
